<template>
  <div :class="className" :style="{height:height,width:width}"></div>

</template>

<script>
import * as echarts from 'echarts';

require('echarts/theme/macarons') // echarts theme

import resize from "./mixins/resize";
export default {
  mixins: [resize],
  name: "Funnel3dChart",
  props: {
    className: {
      type: String,
      default: 'chart'
    },
    width: {
      type: String,
      default: '100%'
    },
    height: {
      type: String,
      default: '400px'
    },
    backgroundColor: {
      type: String,
      default:'#375A88'
    }
  },
  data() {
    return {
      chart: null,
    }
  },mounted() {
    this.$nextTick(() => {
      this.initChart()
    })
  },
  beforeDestroy() {
    if (!this.chart) {
      return
    }
    this.chart.dispose()
    this.chart = null
  },
  methods: {
    initChart() {
      this.chart = echarts.init(this.$el, 'dark')
      this.chart.setOption({
        backgroundColor:this.backgroundColor,
        title: {
          text: 'Funnel'
        },
        tooltip: {
          trigger: 'item',
          formatter: '{a} <br/>{b} : {c}%'
        },
        toolbox: {
          feature: {
            dataView: { readOnly: false },
            restore: {},
            saveAsImage: {}
          },
        },
        legend: {
          data: ['Show', 'Click', 'Visit', 'Inquiry', 'Order']
        },
        series: [
          {
            name: 'Expected',
            type: 'funnel',
            left: '10%',
            width: '80%',
            label: {
              formatter: '{b}Expected'
            },
            labelLine: {
              show: false
            },
            itemStyle: {
              opacity: 0.7
            },
            emphasis: {
              label: {
                position: 'inside',
                formatter: '{b}Expected: {c}%'
              }
            },
            data: [
              { value: 60, name: 'Visit' },
              { value: 40, name: 'Inquiry' },
              { value: 20, name: 'Order' },
              { value: 80, name: 'Click' },
              { value: 100, name: 'Show' }
            ]
          },
          {
            name: 'Actual',
            type: 'funnel',
            left: '10%',
            width: '80%',
            maxSize: '80%',
            label: {
              position: 'inside',
              formatter: '{c}%',
              color: '#fff'
            },
            itemStyle: {
              opacity: 0.5,
              borderColor: '#fff',
              borderWidth: 2
            },
            emphasis: {
              label: {
                position: 'inside',
                formatter: '{b}Actual: {c}%'
              }
            },
            data: [
              { value: 30, name: 'Visit' },
              { value: 10, name: 'Inquiry' },
              { value: 5, name: 'Order' },
              { value: 50, name: 'Click' },
              { value: 80, name: 'Show' }
            ],
            // Ensure outer shape will not be over inner shape when hover.
            z: 100
          }
        ]
      })
    }
  }
}
</script>

<style scoped>

</style>
